<%-- 
    Document   : createMenu
    Created on : 2014-12-25, 17:58:45
    Author     : albertzhu
--%>

<%@ page import="com.tencent.albert.weixin.driver.bean.*" %>
<%@ page import="com.tencent.albert.weixin.driver.utils.WeixinUtil" %>
<%@ page import="com.tencent.albert.weixin.driver.Constants" %>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%!
    private static Menu getMenu() {
        CommonButton btn11 = new CommonButton();
        btn11.setName("入住登记");
        btn11.setType("click");
        btn11.setKey("i_enterInfo");

        CommonButton btn12 = new CommonButton();
        btn12.setName("物品报修");
        btn12.setType("click");
        btn12.setKey("i_repairInfo");

        CommonButton btn13 = new CommonButton();
        btn13.setName("生活服务");
        btn13.setType("click");
        btn13.setKey("i_serviceInfo");

        CommonButton btn14 = new CommonButton();
        btn14.setName("留言");
        btn14.setType("click");
        btn14.setKey("i_msgInfo");


        CommonButton btn21 = new CommonButton();
        btn21.setName("寻找房源");
        btn21.setType("click");
        btn21.setKey("u_serachRoom");

        CommonButton btn22 = new CommonButton();
        btn22.setName("预约房源");
        btn22.setType("click");
        btn22.setKey("u_reserveRoom");

        

        CommonButton btn31 = new CommonButton();
        btn31.setName("我的现金券");
        btn31.setType("click");
        btn31.setKey("s_myCoupons");

        CommonButton btn33 = new CommonButton();
        btn33.setName("我的朋友");
        btn33.setType("click");
        btn33.setKey("s_myFriends");

        

        CommonButton btn35 = new CommonButton();
        btn35.setName("关于我们");
        btn35.setType("click");
        btn35.setKey("s_aboutUs");

        ViewButton btn32 = new ViewButton();
        btn32.setName("关于我们");
        btn32.setType("view");
        btn32.setUrl("http://www.52xiaoluo.com/play/");

        ComplexButton mainBtn1 = new ComplexButton();
        mainBtn1.setName("入住小螺");
        mainBtn1.setSub_button(new Button[]{btn11, btn12, btn13, btn14});

        ComplexButton mainBtn2 = new ComplexButton();
        mainBtn2.setName("找房子");
        mainBtn2.setSub_button(new Button[]{btn21, btn22});

        ComplexButton mainBtn3 = new ComplexButton();
        mainBtn3.setName("更多");
        mainBtn3.setSub_button(new Button[]{btn31, btn33, btn35, btn32});

        /**
         * 这是公众号xiaoqrobot目前的菜单结构，每个一级菜单都有二级菜单项<br>
         *
         * 在某个一级菜单下没有二级菜单的情况，menu该如何定义呢？<br>
         * 比如，第三个一级菜单项不是“更多体验”，而直接是“幽默笑话”，那么menu应该这样定义：<br>
         * menu.setButton(new Button[] { mainBtn1, mainBtn2, btn33 });
         */
        Menu menu = new Menu();
        menu.setButton(new Button[]{mainBtn1, mainBtn2, mainBtn3});

        return menu;
    }
%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>

        <%
            // 调用接口获取access_token
            AccessToken at = WeixinUtil.getAccessToken(Constants.appId, Constants.appSecret);

            if (null != at) {
                // 调用接口创建菜单
                //int result = WeixinUtil.delMenu(at.getToken());
                int result = 0;
                // 判断菜单创建结果
                if (0 == result) {
                    out.println("菜单删除成功！");
                } else {
                    out.println("菜单删除失败，错误码：" + result);
                }
            }

        %>

    </body>
</html>
